package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.KnowledgeAnswers;
import com.stylefeng.guns.modular.system.service.IKnowledgeAnswersService;

import java.util.Date;

/**
 * 提问表控制器
 *
 * @author fengshuonan
 * @Date 2019-10-07 01:38:45
 */
@Controller
@RequestMapping("/knowledgeAnswers")
public class KnowledgeAnswersController extends BaseController {

    private String PREFIX = "/system/knowledgeAnswers/";

    @Autowired
    private IKnowledgeAnswersService knowledgeAnswersService;

    /**
     * 跳转到提问表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "knowledgeAnswers.html";
    }

    /**
     * 跳转到添加提问表
     */
    @RequestMapping("/knowledgeAnswers_add")
    public String knowledgeAnswersAdd() {
        return PREFIX + "knowledgeAnswers_add.html";
    }

    /**
     * 跳转到修改提问表
     */
    @RequestMapping("/knowledgeAnswers_update/{knowledgeAnswersId}")
    public String knowledgeAnswersUpdate(@PathVariable Integer knowledgeAnswersId, Model model) {
        KnowledgeAnswers knowledgeAnswers = knowledgeAnswersService.selectById(knowledgeAnswersId);
        model.addAttribute("item",knowledgeAnswers);
        LogObjectHolder.me().set(knowledgeAnswers);
        return PREFIX + "knowledgeAnswers_edit.html";
    }

    /**
     * 获取提问表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return knowledgeAnswersService.selectList(null);
    }

    /**
     * 新增提问表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(KnowledgeAnswers knowledgeAnswers) {
        knowledgeAnswers.setState(0);
        knowledgeAnswers.setCreateDate(new Date());
        knowledgeAnswersService.insert(knowledgeAnswers);
        return SUCCESS_TIP;
    }

    /**
     * 删除提问表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer knowledgeAnswersId) {
        knowledgeAnswersService.deleteById(knowledgeAnswersId);
        return SUCCESS_TIP;
    }

    /**
     * 修改提问表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(KnowledgeAnswers knowledgeAnswers) {
        knowledgeAnswersService.updateById(knowledgeAnswers);
        return SUCCESS_TIP;
    }

    /**
     * 提问表详情
     */
    @RequestMapping(value = "/detail/{knowledgeAnswersId}")
    @ResponseBody
    public Object detail(@PathVariable("knowledgeAnswersId") Integer knowledgeAnswersId) {
        return knowledgeAnswersService.selectById(knowledgeAnswersId);
    }
}
